﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pseudogenerator.Common.Generators;
using Pseudogenerator.Common.ViewModels.Core;

namespace Pseudogenerator.Common.ViewModels
{
    public class OneSetMixViewModel
        : WorkSpaceViewModel<OneSetMix>
    {
        public OneSetMixViewModel()
        {
            ModeloActual = new OneSetMix();
        }

        #region Model Fields


        public uint m
        {
            get
            {
                return ModeloActual.m;
            }
            set
            {
                if (ModeloActual.m == value)
                    return;
                ModeloActual.m = value;
                OnPropertyChanged();
                RefreshGUI();
            }
        }

        public uint k
        {
            get
            {
                return ModeloActual.k;
            }
            set
            {
                if (ModeloActual.k == value)
                    return;
                ModeloActual.k = value;
                OnPropertyChanged();
                RefreshGUI();
            }
        }

        #endregion

        public override bool CanRun
        {
            get
            {
                return !InWorkProgress && ModeloActual.CanGenerateNext;
            }
        }

        private OneSetMix _ModeloActual = null;
        public override OneSetMix ModeloActual
        {
            get
            {
                if (_ModeloActual == null)
                    _ModeloActual = new OneSetMix();

                return _ModeloActual;
            }
            set
            {
                if (value == null)
                    return;

                this.m = value.m;
                this.k = value.k;
                ClearCommand.Execute(null);
            }
        }



        public override string Title
        {
            get { return "Mezcla de una serie"; }
        }

        public override IEnumerable<string> Errors
        {
            get 
            {
                if (k <= 16)
                    yield return "'k' debe ser mayor que 16";

                if (m <= k)
                    yield return "'m' debe ser mayor que 'k'";
            }
        }

        public override IEnumerable<string> Recommendations
        {
            get 
            {
                return new List<string>();
            }
        }

        protected override void AddPreload()
        {
            var actual = Preloads.FirstOrDefault(i => i.k== k && i.m == m);
            if (actual == null)
            {
                Preloads.Add(new OneSetMix() {k = k, m = m });
            }
        }
    }
}
